package com.thb.pay.mapper;

import com.thb.pay.db.mapper.SuperBaseMapper;
import com.thb.pay.entity.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 系统-资源表 Mapper 接口
 * </p>
 *
 * @author lucky
 * @since 2019-07-21
 */
@Mapper
public interface SysResourceMapper extends SuperBaseMapper<SysResource> {

    @Select(value = " SELECT DISTINCT (s.id), s.* " +
            " FROM " + SysUser.TABLE_NAME + " AS u " +
            " JOIN " + SysUserRole.TABLE_NAME + " AS ur ON u.id = ur.user_id " +
            " JOIN " + SysRole.TABLE_NAME + " AS r ON ur.role_id = r.id " +
            " JOIN " + SysPermission.TABLE_NAME + " AS p ON p.role_id = r.id " +
            " JOIN " + SysResource.TABLE_NAME + " AS s ON s.id = p.resource_id " +
            " WHERE 1 = 1 " +
            " AND u.id = #{userId} " +
            " AND s.status = 1 " +
            " AND s.del_flag = 0 " +
            " ORDER BY s.order_num ASC ")
    List<SysResource> selectListByUserId(@Param("userId") Long userId);
}
